package cn.plushine.service;

import cn.plushine.mapper.BaseBrandMapper;
import cn.plushine.pojo.Brand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 品牌信息
 */
@Service
public class BaseBrandServiceImpl implements BaseBrandService {

    @Autowired
    BaseBrandMapper baseBrandMapper;

    // 获取品牌列表
    @Override
    public List<Brand> getBrandList(int index, int size, String input) throws Exception {
        List<Brand> brandListDB = baseBrandMapper.getBrandList(index, size, input);
        // bug-fixed：查询结果完全可能为null
        return brandListDB;
    }

    // 获取品牌总数目
    @Override
    public int getBrandTotal(String input) {
        return baseBrandMapper.getBrandTotal(input);
    }

    // 添加品牌信息
    @Override
    public int save(Brand brand) throws Exception {
        int saveDB = baseBrandMapper.save(brand);
        // 返回值为影响的行数
        if (saveDB != 0) {
            // 添加成功
            return saveDB;
        }
        throw new Exception("品牌信息添加失败！");
    }

    // 更新品牌信息
    @Override
    public int update(Brand brand) throws Exception {
        int updateDB = baseBrandMapper.update(brand);
        if (updateDB != 0) {
            return updateDB;
        }
        throw new Exception("更新品牌信息失败！");
    }


    // 删除品牌信息
    @Override
    public int delete(int id) throws Exception {
        int deleteDB = baseBrandMapper.delete(id);
        if (deleteDB != 0) {
            return deleteDB;
        }
        throw new Exception("删除品牌信息失败！");
    }
}
